<?php
class ElementsController extends Zend_Controller_Action
{	
    public function bestProductAction(){
        $model = new Vina_Model_Products();
        $data = $model->fetchListToArray("is_best = 1", "id desc", 12);
        $this->view->data = $data;
    }
    
    public function categoriesAction()
    {
        $category = new Vina_Model_Categories();
        $data = $category->fetchListToArray('1=1', 'order asc');
        
        $this->view->data = $data;
   
    }
    public function footerAction(){
        $model = new Vina_Model_Configs();
        $data = $model->find(1);
    
        $this->view->config = $data;
    }
    public function bannerAction(){
        $model = new Vina_Model_Configs();
        $data = $model->find(1);
        $this->view->config = $data;
    }
    
    public function homeFooterAction()
    {
     $modelAbout = new Vina_Model_Abouts();
     $dataAbout = $modelAbout->fetchListToArray("type = 'about'", 'id desc', 1);
     $dataService = $modelAbout->fetchListToArray("type = 'service'", 'id desc', 3);
     //datanew
     $modelNews = new Vina_Model_News();
     $dataNews = $modelNews->fetchListToArray("1=1",'id desc', 6);
     
     //setview
     $this->view->dataAbout = $dataAbout[0];
     $this->view->dataService = $dataService;
     $this->view->dataNews = $dataNews;
     
    }
    public function slidehomeAction()
    {
		$model = new Vina_Model_DeveloperMapper();
        $data = $model->listSlideHome();
       
        $this->view->data = $data;
    }
    
    
    public function supportsAction()
    {
       $model = new Vina_Model_Supports();
       $data = $model->fetchListToArray("1=1", "id desc", 1);
       $this->view->data = $data[0];
    }
    
    
    
   
    public function searchAction()
    {
        $category = new Vina_Model_Categories();
        $data = $category->fetchListToArray('1=1','id asc');
        $this->view->dataCategory = $data;
    }
    
	public function categoriessbAction()
    {
		$model = new Vina_Model_Categories();
        $data = $model->fetchListToArray("category_id=0", "id asc");
        foreach($data as $key=>$value):
            $modelPro = new Vina_Model_Products();
            $dataRe[$key]['name'] = $value['name'];
            $dataRe[$key]['name_en'] = $value['name_en'];
            $dataRe[$key]['name_china'] = $value['name_china'];
            $dataRe[$key]['id'] = $value['id'];
            $dataRe[$key]['products'] = $model->fetchListToArray("category_id = {$value['id']}");
            
        endforeach;
        $this->view->data = $dataRe;
        
    }
    public function textlinkAction()
    {
		$model = new Vina_Model_Textlink();
        $data = $model->fetchListToArray('1=1','id asc');
        $this->view->data = $data;
    }
    
    public function slideproAction()
    {
        $SS = new Zend_Session_Namespace ('Default');
        $category_id = $SS->category_id;
		$model = new Vina_Model_Slides();
        $data = $model->fetchListToArray("category_id = $category_id",'id asc');
        if($data == NULL) {
            $data = $model->fetchListToArray("1=1",'id asc');
        }
        $this->view->data = $data;
    }
    
    public function partnerAction(){
        $model = new Vina_Model_Advertisements();
        $data = $model->fetchListToArray("align=2", "id desc");
        $this->view->data = $data;
    }
    public function videosbAction(){
        $model = new Vina_Model_Configs();
        $data = $model->find(1);
        $this->view->config = $data;
    }
    public function newssbAction(){
        $news                    = new Vina_Model_News();
        
        $where = "category_id = 2";
        $dataNews                = $news->fetchListToArray($where, 'id desc', 10);
        $this->view->data = $dataNews;
    }
    
   	public function menutopAction(){
   	    $modelCategory = new Vina_Model_Categories();
        $dataCategoryNew = $modelCategory->fetchListToArray("category_id = 37", "order asc");
        $this->view->data = $dataCategoryNew;
   	}
}
